package com.jingxi.controller;

import com.jingxi.model.TbItemCat;
import com.jingxi.service.TbItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/item/cat")
public class ItemCatController {
    @Autowired
    TbItemCatService tbItemCatService;
    @SuppressWarnings({"rawtypes","unchecked"})//抑制多类型的警告：
    @RequestMapping("/list")
    @ResponseBody
    public List getTbItemCatList(@RequestParam(value = "id",defaultValue = "0")Long id)throws Exception
    {
        List licat=new ArrayList();
        List<TbItemCat>li=tbItemCatService.getTbItemCatList(id);
        for (TbItemCat tbItemCat:li){
            Map map=new HashMap();
            map.put("id",tbItemCat.getId());
            map.put("text",tbItemCat.getName());
            map.put("state",tbItemCat.getIsParent()?"closed":"open");
            licat.add(map);
        }
        return licat;
    }

}
